/**
 * 文件：BaseMenu.java
 * 说明：基础菜单
 * 作者：古通基
 * 时间：2011-09-14
 */

package com.java.component;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class BaseMenu implements ActionListener
{
	private JFrame baseframe = null;                         //主框架
	private JMenuBar baseMenuBar = null;               //菜单栏
	
	private JMenu file = null;                                    //文件菜单
    private JMenuItem file_con,file_to,file_from,file_exit;
    
    private JMenu stu = null;                                   //学生菜单
    private JMenuItem stu_insert,stu_deleted,stu_update,stu_query;
    
    private JMenu course = null;                             //课程菜单
    private JMenuItem course_insert,course_update,course_query;
    
    private JMenu score = null;                               //成绩菜单
    private JMenuItem score_insert,score_update,score_query;
    
    private JMenu accom = null;                             //住宿菜单
    private JMenuItem accom_insert,accom_update,accom_query;
    
    private JMenu cost = null;                                //缴费菜单
    private JMenuItem cost_insert,cost_update,cost_query;
    
    private JMenu about = null;                             //关于菜单
    private JMenuItem about_author,about_system,about_help;
    
    private ConDataBasePanel condatabasepanel = new ConDataBasePanel();
    
    private InsertStuPanel insertstupanel = new InsertStuPanel();                                  //学生-->添加 对话
    private QueryStuPanel querystupanel = new QueryStuPanel();                                //学生-->查询 对话
    private ModifyStuPanel modifystupanel = new ModifyStuPanel();                           //学生-->修改 对话
    private DeleteStuPanel deletestupanel = new DeleteStuPanel();                               //学生-->删除 对话
    
    private QueryCoursePanel querycoursepanel = new QueryCoursePanel();                //课程-->查询 对话
    private InsertCoursePanel insertcoursepanel = new InsertCoursePanel();                 //课程-->添加 对话
    private ModifyCoursePanel modifycoursepanel= new ModifyCoursePanel();           //课程-->修改 对话
    
    private InsertScorePanel insertscorepanel = new InsertScorePanel();                      //成绩-->添加 对话
    private ModifyScorePanel modifyscorepanel = new ModifyScorePanel();               //成绩-->修改 对话
    private QueryScorePanel queryscorepanel = new QueryScorePanel();                    //成绩-->查询 对话
    
    private InsertAccomPanel insertaccompanel = new InsertAccomPanel();                      //住宿-->添加 对话
    private ModifyAccomPanel modifyaccompanel = new ModifyAccomPanel();               //住宿-->修改 对话
    private QueryAccomPanel queryaccompanel = new QueryAccomPanel();                    //住宿-->查询 对话
    
    private InsertCostPanel insertcostpanel = new InsertCostPanel();                      //缴费-->添加 对话
    private ModifyCostPanel modifycostpanel = new ModifyCostPanel();               //缴费-->修改 对话
    private QueryCostPanel querycostpanel = new QueryCostPanel();                    //缴费-->查询 对话
     
    public BaseMenu(JFrame baseframe)                                    //构造方法
    {
    	this.baseframe = baseframe;
    	baseMenuBar = new JMenuBar();
    	baseframe.setJMenuBar(baseMenuBar);
    	AddMenu();
    	AddListener();
    	baseframe.setVisible(true);                                                //刷新窗口
    }

    private void AddMenu()
    {
    	file = new JMenu("文件");                                                 //添加文件菜单
    	baseMenuBar.add(file);  
    	file.add(file_con = new JMenuItem("连接"));
    	file.addSeparator();
    	file.add(file_to = new JMenuItem("备份"));
    	file.addSeparator();
    	file.add(file_from = new JMenuItem("还原"));
    	file.addSeparator();
    	file.add(file_exit = new JMenuItem("退出"));
    	
    	stu = new JMenu("学生");                                                 //添加学生菜单
    	baseMenuBar.add(stu);  
    	stu.add(stu_insert = new JMenuItem("添加"));
    	stu.addSeparator();
    	stu.add(stu_deleted = new JMenuItem("删除"));
    	stu.addSeparator();
    	stu.add(stu_update = new JMenuItem("修改"));
    	stu.addSeparator();
    	stu.add(stu_query = new JMenuItem("查询"));
    	
    	
    	course = new JMenu("课程");                                                //添加课程菜单
    	baseMenuBar.add(course);  
    	course.add(course_insert = new JMenuItem("添加"));
    	course.addSeparator();
    	course.add(course_update = new JMenuItem("修改"));
    	course.addSeparator();
    	course.add(course_query = new JMenuItem("查询"));
    	
    	score = new JMenu("成绩");                                                //添加成绩菜单
    	baseMenuBar.add(score);  
    	score.add(score_insert = new JMenuItem("添加"));
    	score.addSeparator();
    	score.add(score_update = new JMenuItem("修改"));
    	score.addSeparator();
    	score.add(score_query = new JMenuItem("查询"));
    	
    	accom = new JMenu("住宿");                                                //添加住宿菜单
    	baseMenuBar.add(accom);  
    	accom.add(accom_insert = new JMenuItem("添加"));
    	accom.addSeparator();
    	accom.add(accom_update = new JMenuItem("修改"));
    	accom.addSeparator();
    	accom.add(accom_query = new JMenuItem("查询"));
    	
    	cost = new JMenu("缴费");                                                //添加缴费菜单
    	baseMenuBar.add(cost);  
    	cost.add(cost_insert = new JMenuItem("添加"));
    	cost.addSeparator();
    	cost.add(cost_update = new JMenuItem("修改"));
    	cost.addSeparator();
    	cost.add(cost_query = new JMenuItem("查询"));
    	
    	about = new JMenu("关于");                                              //添加关于菜单
    	baseMenuBar.add(about);  
    	about.add(about_system = new JMenuItem("系统"));
    	about.addSeparator();
    	about.add(about_author = new JMenuItem("作者"));
    	about.addSeparator();
    	about.add(about_help = new JMenuItem("帮助"));
    }  
    private void AddListener()
    {
    	file_con.addActionListener(this);                                         //监听文件菜单 
    	file_to.addActionListener(this);                                              
    	file_from.addActionListener(this);
    	file_exit.addActionListener(this);
    	
    	stu_insert.addActionListener(this);                                    //监听学生菜单
    	stu_deleted.addActionListener(this); 
    	stu_update.addActionListener(this); 
    	stu_query.addActionListener(this); 
    	
    	score_insert.addActionListener(this);                                //监听成绩菜单
    	score_update.addActionListener(this); 
    	score_query.addActionListener(this); 
    	
    	course_insert.addActionListener(this);                            //监听课程菜单
    	course_update.addActionListener(this); 
    	course_query.addActionListener(this); 
    	
    	accom_insert.addActionListener(this);                           //监听住宿菜单
    	accom_update.addActionListener(this); 
    	accom_query.addActionListener(this); 
    	
    	cost_insert.addActionListener(this);                           //监听缴费菜单
    	cost_update.addActionListener(this); 
    	cost_query.addActionListener(this); 
    	
    	about_system.addActionListener(this);                         //监听关于菜单
    	about_author.addActionListener(this);
    	about_help.addActionListener(this);
    }    
	public void actionPerformed(ActionEvent e)                  //事件处理方法          
	{
		if(e.getSource()==stu_insert)                                      //学生-->添加
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("添加学生信息");
			dialog.getContentPane().add(insertstupanel);
			dialog.setVisible(true);
		}	
		else if(e.getSource()==stu_deleted)                           //学生-->删除
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("删除学生信息");
			dialog.getContentPane().add(deletestupanel);
			dialog.setVisible(true);
		}
		else if(e.getSource()==stu_update)                           //学生-->修改
		{ 
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("修改学生信息");
			dialog.getContentPane().add(modifystupanel);
			dialog.setVisible(true);
		}
		else if(e.getSource()==stu_query)                             //学生-->查询
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("查询学生信息");
			dialog.getContentPane().add(querystupanel);
			dialog.setVisible(true);
		}			
		else if(e.getSource()==course_query)                                   //课程-->查询
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("课程查询");
			dialog.getContentPane().add(querycoursepanel);
			dialog.setVisible(true);
		}	
		else if(e.getSource()==course_insert)                                  //课程-->添加
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("课程添加");
			dialog.getContentPane().add(insertcoursepanel);
			dialog.setVisible(true);
		}	
		else if(e.getSource()==course_update)                               //课程-->修改
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("课程修改");
			dialog.getContentPane().add(modifycoursepanel);
			dialog.setVisible(true);
		}
		
		else if(e.getSource()==score_insert)                                  //成绩-->添加
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("添加成绩");
			dialog.getContentPane().add(insertscorepanel);
			dialog.setVisible(true);
		}	
		
		else if(e.getSource()==score_update)                                //成绩-->修改
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("修改成绩");
			dialog.getContentPane().add(modifyscorepanel);
			dialog.setVisible(true);
		}	
		
		else if(e.getSource()==score_query)                                //成绩-->查看
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("查看成绩");
			dialog.getContentPane().add(queryscorepanel);
			dialog.setVisible(true);
		}	
		
		else if(e.getSource()==accom_insert)                                  //住宿-->添加
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("添加住宿");
			dialog.getContentPane().add(insertaccompanel);
			dialog.setVisible(true);
		}	
		
		else if(e.getSource()==accom_update)                                //住宿-->修改
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("修改住宿");
			dialog.getContentPane().add(modifyaccompanel);
			dialog.setVisible(true);
		}	
		
		else if(e.getSource()==accom_query)                                //住宿-->查看
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("查看住宿");
			dialog.getContentPane().add(queryaccompanel);
			dialog.setVisible(true);
		}	
		
		else if(e.getSource()==cost_insert)                                  //缴费-->添加
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("添加缴费");
			dialog.getContentPane().add(insertcostpanel);
			dialog.setVisible(true);
		}	
		
		else if(e.getSource()==cost_update)                                //缴费-->修改
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("修改缴费");
			dialog.getContentPane().add(modifycostpanel);
			dialog.setVisible(true);
		}	
		
		else if(e.getSource()==cost_query)                                //缴费-->查看
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 360);
			dialog.setLocation(300,200);
			dialog.setTitle("查看缴费");
			dialog.getContentPane().add(querycostpanel);
			dialog.setVisible(true);
		}	
		
		else if(e.getSource()==file_con)                                        //文件-->连接              
		{
			JDialog dialog = new JDialog(baseframe,true);
			dialog.setSize(320, 270);
			dialog.setLocation(300,200);
			dialog.setTitle("链接数据库");
			dialog.getContentPane().add(condatabasepanel);
			dialog.setVisible(true);
		}
		else if(e.getSource()==file_exit)                                       //文件-->退出              
		{
			System.exit(0);
		}
		else if(e.getSource()==about_system)                             //关于-->系统
		{
				JOptionPane.showMessageDialog(baseframe, "学生信息管理系统 版本1.0 Beta", "关于系统",JOptionPane.INFORMATION_MESSAGE);
		}
		else if(e.getSource()==about_author)                             //关于-->作者
		{
			JOptionPane.showMessageDialog(baseframe, "E-mail：ishagua@gmail.com", "关于作者", JOptionPane.INFORMATION_MESSAGE);
		}
		else if(e.getSource()==about_help)                                //关于-->帮助
		{
			JOptionPane.showMessageDialog(baseframe, "请联系QQ：84197902", "关于帮助", JOptionPane.INFORMATION_MESSAGE);
		}
	}
}
